package k8s

import (
	"k8s.io/client-go/kubernetes"
	"flag"
	"k8s.io/client-go/tools/clientcmd"
	"log"
	"fmt"
	"k8s.io/client-go/rest"
)

var clientset *kubernetes.Clientset
var DynamicConfig *rest.Config


func init()  {
	k8sconfig := flag.String("k8sconfig","./conf/k8sconfig","kubernetes config file path")
	//k8sconfig := "./conf/k8sconfig"
	flag.Parse()
	config , err := clientcmd.BuildConfigFromFlags("",*k8sconfig)
	if err != nil {
		log.Println(err)
	}
	clientset , err = kubernetes.NewForConfig(config)
	if err != nil {
		log.Fatalln(err)
	} else {
		fmt.Println("clientset connect k8s success")
	}

	//dynamic client connect to k8s config
	DynamicConfig , err = clientcmd.BuildConfigFromFlags("",*k8sconfig)
	if err != nil {
		log.Println("DynamicConfig init error: ",err.Error())
	}
}